package com.ruoyi.project.system.product.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.product.domain.ZzProduct;
import com.ruoyi.project.system.product.service.IZzProductService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2020-10-29
 */
@Controller
@RequestMapping("/system/product")
public class ZzProductController extends BaseController
{
    private String prefix = "system/product";

    @Autowired
    private IZzProductService zzProductService;

    @RequiresPermissions("system:product:view")
    @GetMapping()
    public String product()
    {
        return prefix + "/product";
    }

    //根据productId查询商品
    @RequiresPermissions("system:product:findOneProduct")
    @PostMapping("/findOneProduct")
    @ResponseBody
    public ZzProduct findOneProduct(Integer productId) {
        return zzProductService.selectZzProductById(productId);
    }

    //查询商品信息
    @RequiresPermissions("system:product:findAllProduct")
    @PostMapping("/findAllProduct")
    @ResponseBody
    public List<ZzProduct> findAllProduct() {
        return zzProductService.findAll();
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("system:product:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZzProduct zzProduct)
    {
        startPage();
        List<ZzProduct> list = zzProductService.selectZzProductList(zzProduct);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("system:product:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZzProduct zzProduct)
    {
        List<ZzProduct> list = zzProductService.selectZzProductList(zzProduct);
        ExcelUtil<ZzProduct> util = new ExcelUtil<ZzProduct>(ZzProduct.class);
        return util.exportExcel(list, "product");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("system:product:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZzProduct zzProduct)
    {
        return toAjax(zzProductService.insertZzProduct(zzProduct));
    }

    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{productId}")
    public String edit(@PathVariable("productId") Integer productId, ModelMap mmap)
    {
        ZzProduct zzProduct = zzProductService.selectZzProductById(productId);
        mmap.put("zzProduct", zzProduct);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("system:product:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZzProduct zzProduct)
    {
        return toAjax(zzProductService.updateZzProduct(zzProduct));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("system:product:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zzProductService.deleteZzProductByIds(ids));
    }
}
